from selenium.webdriver.common.by import By

from Page.Page import Page


class Page1(Page):
    #页面元素的定位

    #对我的酒仙进行定位  /html/body/div[2]/div/div[2]/ul/li[1]/div[1]/a
    myjiuxian_loc=(By.XPATH,'//a[@href="https://member.jiuxian.com/index.htm"]')
    #打开新的窗口，
    #将页面弹窗去掉  class="uGuideClose"
    close_loc=(By.CLASS_NAME,'uGuideClose')
    #向下滑动800像素
    #对收货地址进行定位  /html/body/div[4]/div[1]/div[2]/div[4]/a[3]/span
    shouhuo_loc=(By.XPATH,'/html/body/div[4]/div[1]/div[2]/div[4]/a[3]/span')
    #对添加新地址进行定位  class addressTrue
    newaddress_loc=(By.CLASS_NAME,'addressTrue')
    # 对收货人进行定位 id people
    addpeople_loc=(By.ID,'people')
    # 选择地区 省 id="province" value="2"
    province_loc = (By.ID, 'province')
    # 选择地区 市 id="city" index="1"
    city_loc = (By.ID, 'city')
    # 选择地区 县 id="district" 昌平区
    district_loc = (By.ID, 'district')

    # 输入详细地址 id="address" name="addressMore"
    addressMore_loc = (By.NAME, 'addressMore')
    # 输入邮政编码
    zipcode_loc = (By.ID, 'zipcode')
    # 输入手机号 id="iphone" name="mobile"
    mobile_loc = (By.NAME, 'mobile')
    # 点击提交 class="qjwSubmit2"
    qjwSubmit2 = (By.CLASS_NAME, 'qjwSubmit2')

    # 点击确定
    binggo_loc = (By.XPATH, '/html/body/div[8]/div/div[3]/span[1]/b')

    #页面元素的封装方法

    # 对我的酒仙进行点击操作
    def myjiuxian(self):
        self.click(self.myjiuxian_loc)
    # 将页面弹窗进行点击操作
    def close(self):
        self.click(self.close_loc)
    # 对收货地址进行点击操作
    def shouhuo(self):
        self.click(self.shouhuo_loc)
    # 对添加新地址进行点击操作
    def newaddress(self):
        self.click(self.newaddress_loc)
    # 对收货人进行输入操作
    def addpeople(self):
        self.send_keys(self.addpeople_loc,'天天')

    # 选择地区 省
    def province(self):
        self.select_value(self.province_loc, '2')

    # 选择地区 市
    def city(self):
        self.select_index(self.city_loc, 1)

    # 选择地区 县
    def district(self):
        self.select_text(self.district_loc, '昌平区')

    # 输入详细地址
    def addressMore(self):
        self.send_keys(self.addressMore_loc, '北京八维')

    # 输入邮政编码
    def zipcode(self):
        self.send_keys(self.zipcode_loc, '100000')

    # 输入手机号
    def mobile(self):
        self.send_keys(self.mobile_loc, '15253006116')

    # 提交
    def submit(self):
        self.click(self.qjwSubmit2)

    # 点击确定
    def bingo(self):
        self.click(self.binggo_loc)
    #业务逻辑
    def jiuxian_luoji2(self):
        self.jiuxian_luoji()
        #1.我的酒仙
        self.myjiuxian()
        #2.打开新的窗口
        self.new_window()
        #3.关闭
        self.close()
        #4.向下滑动800像素
        self.scroll_x('800')
        #5.收货地址
        self.shouhuo()
        #6.添加新的收货地址
        self.newaddress()
        #7.收货人
        self.addpeople()
        #8.地区
        self.province()
        #9.城市
        self.city()
        #10.区
        self.district()
        #详细地址
        self.addressMore()
        #邮政编码
        self.zipcode()
        #电话号
        self.mobile()
        #提交
        self.submit()
        #确定
        self.bingo()


